package com.gold.syn;

import java.lang.reflect.Array;
import java.util.Arrays;

public class ThreadSafe {
    private static int index=0;
    public static void main(String[] args) throws InterruptedException {
        String []s=new String[5];
        //创建两个线程
        Runnable runnableA=new Runnable() {
            @Override
            public void run() {
                s[index]="hello";
                index++;
            }
        };
        Runnable runnableB=new Runnable() {
            @Override
            public void run() {
                s[index]="world";
                index++;
            }
        };
        Thread a=new Thread(runnableA,"A");
        Thread b=new Thread(runnableB,"B");
        a.start();
        b.start();

        a.join();
        b.join();
        System.out.println(Arrays.toString(s));

    }
}
